package com.ruoyi.back.controller;

import java.util.List;

import com.ruoyi.back.domain.Information;
import com.ruoyi.back.service.IInformationService;
import com.ruoyi.common.utils.uuid.SnowflakeIdUtils;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资料信息Controller
 * 
 * @author luguanqing
 * @date 2021-04-06
 */
@Api(value="资料信息",description = "资料信息接口")
@RestController
@RequestMapping("/back/information")
public class InformationController extends BaseController
{
    @Autowired
    private IInformationService informationService;

    /**
     * 查询资料信息列表
     */
    //@PreAuthorize("@ss.hasPermi('system:information:list')")
    @ApiOperation(value="查询资料信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "页数", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true, dataType = "String"),
    })
    @GetMapping("/list")
    public TableDataInfo list(Information information)
    {
        startPage();
        List<Information> list = informationService.selectInformationList(information);
        return getDataTable(list);
    }

    /**
     * 导出资料信息列表
     */
    //@PreAuthorize("@ss.hasPermi('system:information:export')")
    @Log(title = "资料信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Information information)
    {
        List<Information> list = informationService.selectInformationList(information);
        ExcelUtil<Information> util = new ExcelUtil<Information>(Information.class);
        return util.exportExcel(list, "information");
    }

    /**
     * 获取资料信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:information:query')")
    @ApiOperation(value="获取资料详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(name="id",value="资料id",required=true)@PathVariable("id") String id)
    {
        return AjaxResult.success(informationService.selectInformationById(id));
    }

    /**
     * 新增资料信息
     */
    //@PreAuthorize("@ss.hasPermi('system:information:add')")
    @ApiOperation(value="新增资料信息")
    @Log(title = "资料信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(name="资料对象",value="传入json格式",required=true)@RequestBody Information information)
    {
        information.setId(String.valueOf(new SnowflakeIdUtils(0, 0).nextId()));
        return toAjax(informationService.insertInformation(information));
    }

    /**
     * 修改资料信息
     */
    //@PreAuthorize("@ss.hasPermi('system:information:edit')")
    @ApiOperation(value="修改资料信息")
    @Log(title = "资料信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(name="资料对象",value="传入json格式",required=true)@RequestBody Information information)
    {
        return toAjax(informationService.updateInformation(information));
    }

    /**
     * 浏览记录+1
     */
    //@PreAuthorize("@ss.hasPermi('system:information:edit')")
    @ApiOperation(value="浏览记录+1")
    @Log(title = "资料信息", businessType = BusinessType.UPDATE)
    @GetMapping(value = "/visitUp/{id}")
    public AjaxResult visitUp(@ApiParam(name="id",value="资料id",required=true)@PathVariable("id") String id)
    {
        return toAjax(informationService.updateVisit(id));
    }

    /**
     * 下载记录+1
     */
    //@PreAuthorize("@ss.hasPermi('system:information:edit')")
    @ApiOperation(value="下载记录+1")
    @Log(title = "资料信息", businessType = BusinessType.UPDATE)
    @GetMapping(value = "/downUp/{id}")
    public AjaxResult downUp(@ApiParam(name="id",value="资料id",required=true)@PathVariable("id") String id)
    {
        return toAjax(informationService.updateDownTime(id));
    }

    /**
     * 删除资料信息
     */
    //@PreAuthorize("@ss.hasPermi('system:information:remove')")
    @ApiOperation(value="删除资料信息")
    @Log(title = "资料信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam(name="id",value="资料id",required=true)@PathVariable String[] ids)
    {
        return toAjax(informationService.deleteInformationByIds(ids));
    }
}
